package com.itwn.portal.service;

import com.alibaba.fastjson.JSON;
import com.itwn.portal.utils.RedisUtil;
import com.itwn.portal.vo.UserHistoryVo;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
@Service
public class HistoryService {
    /**
     *
     * @param history
     */
    public void setHistory(UserHistoryVo history){
        Jedis jedis = RedisUtil.getJedis();
        String key=history.getUid()+"&"+history.getRid();
        String value= JSON.toJSONString(history);
        jedis.set(key,value);
        RedisUtil.close(jedis);
    }

    /**
     *
     * @param uid
     * @param rid
     * @return
     */
    public UserHistoryVo getHistory(Integer uid,Integer rid){
        Jedis jedis = RedisUtil.getJedis();
        String key=uid+"&"+rid;
        String value=jedis.get(key);
        UserHistoryVo historyVo = JSON.parseObject(value, UserHistoryVo.class);
        RedisUtil.close(jedis);
        return historyVo;
    }
}
